package com.yc.jpyy.mobile.controller;

import java.io.UnsupportedEncodingException;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yc.jpyy.base.bean.RestResponse;
import com.yc.jpyy.mobile.dao.BizDao;
import com.yc.jpyy.mobile.service.BizService;

@Controller
@RequestMapping(value = "/student")
public class GetStudyRecordController {
	
	@Autowired
	private BizService bizService;

	@Autowired
	private BizDao bizDao;
	
	private static Logger logger = LoggerFactory.getLogger(GetClassInformation.class);

	
	/**
	 * 获取视频学习记录
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getVideoRecordList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getVideoRecordList(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();

		try {
			// 用户Id
			String userId = request.getParameter("userId");
			
			if((null != userId && !userId.equals(""))){
				// 查询视频学习记录
				response = bizService.getVideoRecordList(userId,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填字段！");
			}
		} catch (Exception e) {
			logger.info("getVideoRecordList:"+ e.toString());
			response.setReturnMsg(0,"获取视频学习记录失败！");
		} finally {
			return response.toJSON();
		}
	}
	
	/**
	 * 获取模拟考试记录
	 * 
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@SuppressWarnings("finally")
	@RequestMapping(value = "/getExamRecordList", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
	public @ResponseBody String getExamRecordList(HttpServletRequest request)
			throws UnsupportedEncodingException {

		RestResponse response = new RestResponse();

		try {
			// 用户Id
			String userId = request.getParameter("userId");
			
			if((null != userId && !userId.equals(""))){
				// 查询模拟考试记录
				response = bizService.getExamRecordList(userId,response);
			}else{
				response.setErrorcode(1);
				response.setMessage("缺少必填字段！");
			}
		} catch (Exception e) {
			logger.info("getExamRecordList:"+ e.toString());
			response.setReturnMsg(0,"获取模拟考试记录失败！");
		} finally {
			return response.toJSON();
		}
	}

}
